<?php
$this->placeholder("navegacion")->set($this->navegacion($this->nav));
$domConfig = Zend_Registry::get('domConfig');
$perfil = App_Perfil::getInstance();
$perfil->cargar("ADMIN_USUARIOS");
?>
<div align="center">
<?php if ($perfil->crear()){?>
<div align="right" class="buttons">
  <a class="btn btn-primary" href="<?php echo $this->baseUrl("/usuarios/index/ingresar");?>">
  <span class="glyphicon glyphicon-plus-sign"></span> Crear Usuario</a>
</div>
<?php }?>
<?php if(count($this->datos)>0):?>


<table id="table_id" align="center" class="display">
  <thead>
    <tr>
      <th width="10%">Usuario</th>
      <th width="30%">Nombre</th>
      <th width="20%">Direcci&oacute;n/Ubicaci&oacute;n</th>
      <th width="15%">Rol</th>
      <th width="10%">Estado</th>
      <?php if ($perfil->modificar() || $perfil->eliminar() ) {?>
      <th width="15%">Acciones</th>
      <?php }?>
    </tr>
  </thead>
  <tbody>
	<?php foreach ($this->datos as $value):
		$params=App_Util_SafeUrl::encriptar(array("codusuario"=>$value["codusuario"]),true);
	?>

    <tr>
      <td><?php echo $value["nombreusuario"];?></td>
      <td><?php echo $value["nombres"]." ".$value["apellidos"]."<br />".$value["emailexterno"];?></td>
      <td><?php echo $value["direccionresidencia"]."<br />".$value["ubicacion"];?></td>
      <td>
          <?php
              foreach ($value["roles"] as $roles):
                  echo $roles["nombrerol"]."<BR>";
              endforeach;
          ?>
      </td>
      <td><?php echo $domConfig->DOM_ESTADO->$value["estado"];?></td>
      <td>
        <?php
        $tools = new App_Util_ToolButton();
        $tools->addEdit($this->baseUrl("/usuarios/index/ingresar/{$params}"));
        $tools->add($this->baseUrl("/usuarios/index/cambiarestado/{$params}"), "Activar / Inactivar", "glyphicon glyphicon-check", $perfil->cargar("#ADMIN_USUARIOS_ACTIVAR"));
        echo $tools->render();
        ?>
      </td>
    </tr>
  <?php  endforeach;?>
  </tbody>
</table>

<script type="text/javascript">
$(function() {
	var oTable = $('#table_id').dataTable({
		"bJQueryUI": true,
		"bAutoWidth": false,
 		"sPaginationType": "full_numbers",
 		"bStateSave": true,
 		"aoColumns": [
 	 		 			null,
 	 		 			null,
 	 		 			null,
 	 		 			null,
 	 		 			null,
 	 		 			{ "bSortable": false, "bSearchable": false }
 	 		 		 ]
 	 		  		
	});
	$("input[type='search']").addClass("form-control input-sm search-control");
	$("select[name='table_id_length']").addClass("form-control input-sm search-control");
//	oTable.fnSetFilteringDelay();
//	oTable.fnCreateFilters([3]);
	//oTable.fnAssignFilterValues(2, [jsdrse])

});
</script>

<?php else:?>
<br/>
<?php echo $this->mensajes("No existen registros");?>
<?php endif;?>
</div>